package cn.kgm.makeGodV2;

import cn.kgm.makeGodV2.condition.Condition;
import cn.kgm.makeGodV2.condition.LogicalCondition;
import cn.kgm.makeGodV2.condition.TraitRangeCondition;
import cn.kgm.makeGodV2.personalityTag.PersonalityTag;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.*;

/**
 * 标签容器,内部保存系统所有标签
 *
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-16 15:48
 * @Description: cn.kgm.makeGodV2.TagContainer
 */
@Data
@Builder
@NoArgsConstructor
public class TagContainer {

    /**
     * 系统内部标签
     */
    private static final Map<String, PersonalityTag> tagMap = new HashMap<>();

    static {
        // 示例：睚眦必报标签 - 宜人性低且神经质高
        Condition vengeanceCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", null, 20.0), // 宜人性 <= 20
                        new TraitRangeCondition("neuroticism", 70.0, null)   // 神经质 >= 70
                )
        );
        PersonalityTag vengeanceTag = new PersonalityTag(
                "vengeful",
                "睚眦必报",
                "受到伤害时,要找准时机朝着敌人的伤口猛击!",
                vengeanceCondition,
                1
        );
        tagMap.put(vengeanceTag.getId(), vengeanceTag);


        // 示例：豁达大度标签 - 宜人性高且神经质低
        Condition forgivingCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", 80.0, null), // 宜人性 >= 80
                        new TraitRangeCondition("neuroticism", null, 15.0)    // 神经质 <= 30
                )
        );
        PersonalityTag forgivingTag = new PersonalityTag(
                "forgiving",
                "豁达大度",
                "哪怕是被戴上来那传说中的帽子,当然也是要原谅她啦",
                forgivingCondition, 10
        );
        tagMap.put(forgivingTag.getId(), forgivingTag);

        // 示例：豁达大度标签 - 宜人性高且神经质低
        Condition goodMAanCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", 90.0, null) // 宜人性 >= 80
                )
        );
        PersonalityTag goodManTag = new PersonalityTag(
                "goodMan",
                "好人",
                "对不起,你是个好人! 女孩低着头将你送的礼物双手奉还,随即跑开了...",
                goodMAanCondition,
                10
        );
        tagMap.put(goodManTag.getId(), goodManTag);

        // 1. 知恩图报 - 高宜人性 + 高尽责性
        Condition gratefulCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", 80.0, null), // 宜人性 >= 80
                        new TraitRangeCondition("conscientiousness", 70.0, null) // 尽责性 >= 70
                )
        );
        PersonalityTag gratefulTag = new PersonalityTag(
                "grateful",
                "知恩图报",
                "滴水之恩，当涌泉相报。你从不忘记他人的恩情，总是寻找机会回报。",
                gratefulCondition,
                15
        );
        tagMap.put(gratefulTag.getId(), gratefulTag);

        // 2. 木讷呆滞 - 低开放性 + 低外向性
        Condition dullCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("openness", null, 30.0), // 开放性 <= 30
                        new TraitRangeCondition("extraversion", null, 25.0) // 外向性 <= 25
                )
        );
        PersonalityTag dullTag = new PersonalityTag(
                "dull",
                "木讷呆滞",
                "反应迟钝，不善言辞，常常需要比别人更多的时间来理解事物,但偶尔的灵机一动却能撼动别人的内心。",
                dullCondition,
                5
        );
        tagMap.put(dullTag.getId(), dullTag);

// 3. 奸诈狡猾 - 低宜人性 + 高开放性
        Condition cunningCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", null, 30.0), // 宜人性 <= 30
                        new TraitRangeCondition("openness", 70.0, null) // 开放性 >= 70
                )
        );
        PersonalityTag cunningTag = new PersonalityTag(
                "cunning",
                "奸诈狡猾",
                "你心思缜密，善于算计，总能找到最有利于自己的方式解决问题。",
                cunningCondition,
                10
        );
        tagMap.put(cunningTag.getId(), cunningTag);

// 4. 恶贯满盈 - 极低宜人性 + 高神经质
        Condition evilCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", null, 10.0), // 宜人性 <= 10
                        new TraitRangeCondition("neuroticism", 80.0, null) // 神经质 >= 80
                )
        );
        PersonalityTag evilTag = new PersonalityTag(
                "evil",
                "恶贯满盈",
                "你作恶多端，心狠手辣，视人命如草芥，所到之处无不令人闻风丧胆。",
                evilCondition,
                20
        );
        tagMap.put(evilTag.getId(), evilTag);

// 5. 老魔 - 极低宜人性 + 高开放性 + 高神经质
        Condition oldDevilCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", null, 15.0), // 宜人性 <= 15
                        new TraitRangeCondition("openness", 75.0, null), // 开放性 >= 75
                        new TraitRangeCondition("neuroticism", 70.0, null) // 神经质 >= 70
                )
        );
        PersonalityTag oldDevilTag = new PersonalityTag(
                "old_devil",
                "老魔",
                "你修行千年，心性早已扭曲，行事乖张，不按常理出牌，是修真界人人忌惮的老魔头。",
                oldDevilCondition,
                25
        );
        tagMap.put(oldDevilTag.getId(), oldDevilTag);

// 6. 浩然正气 - 高宜人性 + 高尽责性 + 低神经质
        Condition righteousCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("agreeableness", 80.0, null), // 宜人性 >= 80
                        new TraitRangeCondition("conscientiousness", 75.0, null), // 尽责性 >= 75
                        new TraitRangeCondition("neuroticism", null, 30.0) // 神经质 <= 30
                )
        );
        PersonalityTag righteousTag = new PersonalityTag(
                "righteous",
                "浩然正气",
                "你心怀正义，行事光明磊落，一身正气令邪祟不敢近身。",
                righteousCondition,
                20
        );
        tagMap.put(righteousTag.getId(), righteousTag);

// 7. 八面玲珑 - 高外向性 + 高宜人性
        Condition smoothCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("extraversion", 75.0, null), // 外向性 >= 75
                        new TraitRangeCondition("agreeableness", 70.0, null) // 宜人性 >= 70
                )
        );
        PersonalityTag smoothTag = new PersonalityTag(
                "smooth",
                "八面玲珑",
                "你善于交际，处事圆滑，无论在何种场合都能游刃有余。",
                smoothCondition,
                15
        );
        tagMap.put(smoothTag.getId(), smoothTag);

// 8. 心魔缠身 - 高神经质 + 低尽责性
        Condition demonHeartCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("neuroticism", 85.0, null), // 神经质 >= 85
                        new TraitRangeCondition("conscientiousness", null, 40.0) // 尽责性 <= 40
                )
        );
        PersonalityTag demonHeartTag = new PersonalityTag(
                "demon_heart",
                "心魔缠身",
                "你内心充满矛盾与挣扎，常常被负面情绪所困扰，修行路上心魔频生。",
                demonHeartCondition,
                15
        );
        tagMap.put(demonHeartTag.getId(), demonHeartTag);

// 9. 道心坚定 - 高尽责性 + 低神经质
        Condition determinedCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("conscientiousness", 85.0, null), // 尽责性 >= 85
                        new TraitRangeCondition("neuroticism", null, 35.0) // 神经质 <= 35
                )
        );
        PersonalityTag determinedTag = new PersonalityTag(
                "determined",
                "道心坚定",
                "你目标明确，意志坚定，修行路上无论遇到何种困难都能坚持不懈。",
                determinedCondition,
                20
        );
        tagMap.put(determinedTag.getId(), determinedTag);

        // 10. 离经叛道 - 高开放性 + 低宜人性
        Condition rebelliousCondition = new LogicalCondition(
                LogicalCondition.Operator.AND,
                Arrays.asList(
                        new TraitRangeCondition("openness", 80.0, null), // 开放性 >= 80
                        new TraitRangeCondition("agreeableness", null, 40.0) // 宜人性 <= 40
                )
        );
        PersonalityTag rebelliousTag = new PersonalityTag(
                "rebellious",
                "离经叛道",
                "你思想独特，不墨守成规，常常挑战传统观念和权威。",
                rebelliousCondition,
                15
        );
        tagMap.put(rebelliousTag.getId(), rebelliousTag);

    }

    public static TagContainer getInstance() {
        return TagInner.tagContainer;
    }

    public Map<String, PersonalityTag> getTagsMap() {
        return tagMap;
    }

    public List<PersonalityTag> getTagsList() {
        return new ArrayList<>(tagMap.values());
    }

    public PersonalityTag getTagById(String id) {
        return tagMap.get(id);
    }

    public PersonalityTag addTag(PersonalityTag tag) {
        return tagMap.put(tag.getId(), tag);
    }

    /**
     * 静态内部类做单例模式
     */
    public static class TagInner {
        public static final TagContainer tagContainer = new TagContainer();
    }
}
